package a2022.a20220720;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lenovo
 * @date 2022/7/20
 */
public class a {


    public static void main(String[] args) {
        System.out.println(shiftGrid(new int[][]{
                {3, 8, 1, 9},
                {19, 7, 2, 5},
                {4, 6, 11, 10},
                {12, 0, 21, 13}}, 5));

    }


    public static List<List<Integer>> shiftGrid(int[][] grid, int k) {
        int[] nums = new int[grid.length * grid[0].length];
        for(int i = 0, iMax = grid.length;i < iMax;i++) {
            for(int j = 0, jMax = grid[0].length;j < jMax;j++) {
                k %= nums.length;
                nums[k++] = grid[i][j];
            }
        }
        k = 0;
        List<List<Integer>> lists = new ArrayList<>(grid.length);
        for(int i = 0, iMax = grid.length;i < iMax;i++) {
            List<Integer> tempList = new ArrayList<>(grid[0].length);
            for(int j = 0, jMax = grid[0].length;j < jMax;j++) {
                tempList.add(nums[k++]);
            }
            lists.add(tempList);
        }
        return lists;
    }
}













